package com.cr.admin.system.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.cr.admin.system.pojo.dto.SysLoginParam;
import com.cr.admin.system.pojo.entity.SysUser;
import com.cr.admin.system.pojo.vo.LoginResultVO;
import com.cr.admin.system.service.ISysLoginService;
import com.cr.common.response.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;

@Api(tags = "10.登录管理")
@RestController
public class SysLoginController {

    @Autowired
    private ISysLoginService sysLoginService;

    @ApiOperation(value = "用户登录")
    @PostMapping("/api/login")
    public JsonResult login(@Validated @RequestBody SysLoginParam sysLoginParam) {
        LoginResultVO loginResultVO = sysLoginService.login(sysLoginParam);
        return JsonResult.success(loginResultVO);
    }

    @ApiOperation(value = "退出登录")
    @PostMapping("/api/logout")
    public JsonResult logout() {
        StpUtil.logout();
        return JsonResult.success();
    }

}
